/**
 * 文字与变量的赋值
 * @type {Object}
 */
let code = {
    "type": "Property",
    "start": 221,
    "end": 235,
    "method": false,
    "shorthand": false,
    "computed": false,
    "key": {
        "type": "Identifier",
        "start": 221,
        "end": 229,
        "name": "required"
    },
    "value": {
        "type": "Literal",
        "start": 231,
        "end": 235,
        "value": true,
        "raw": "true"
    },
    "kind": "init"
}
let _value1 = {
    "type": "Identifier",
    "start": 328,
    "end": 334,
    "name": "String"
}
let _value2 = {
    "type": "Literal",
    "start": 354,
    "end": 358,
    "value": true,
    "raw": "true"
}
let _value3 = {
    "type": "ObjectExpression",
    "start": 189,
    "end": 241,
    "properties": []
}

function is_type(value) {
    let regTel = /^function\s+(\w+)[\w|\s|\(|\)\[\]\{\}]+/
    let str = value + "";
    let arr = str.match(regTel)
    if (arr !== null) {
        return arr[1];
    } else {
        return false;
    }
}
/**
 * [exports description]
 * @param  {[type]} kind  init const var let
 * @param  {[type]} name  键
 * @param  {[type]} value 值
 * @param  {Number} key   1存在键,2不存在
 * @return {[type]}       [description]
 */
module.exports = function(kind,name, value, key = 1) {
    let _code = {};
    if (key == 2) {
        _code = copy_data(_value3);
        _code.properties = value;
    } else {
        _code = copy_data(code);
        _code.kind = kind;
        _code.key.name = name;
        let _value = {};
        if (is_array(value)) {
            _value = _value3;
            _value.properties = value;
        } else {
            let _v = is_type(value);
            if (_v) {
                _value = _value1;
                _value.name = _v;
            } else {
                _value = _value2;
                _value.value = value;
            }
        }
        _code.value = _value;
    }
    return copy_data(_code);
}